package com.zretc.shop.controller;


import com.zretc.shop.entity.Users;
import com.zretc.shop.service.UsersService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController//这个注解 表示 我这个类需要通过http协议进行访问
@RequestMapping("users")//可以通过http://Localhost:7777/

public class UsersController {
    @Resource
    private UsersService usersService;

    @PostMapping("addUser")//可以通过http://localhost:7777/test/query这个路径 访问本类的query方法
    public Object addUser(String username, String password, String nickname) {

        return usersService.addUser(username, password, nickname);
    }

    @PostMapping("delUser")
    public Object delUser(Integer id) {

        return usersService.delUser(id);
    }

    @GetMapping("queryById")
    public Object queryById(Integer id) {
        return usersService.queryById(id);
    }

    @PostMapping("editById")
    public Object editById(Users users) {
        return usersService.editById(users);
    }

    @GetMapping("queryByPage")
    public Object queryByPage(
            @RequestParam(required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(required = false, defaultValue = "") String username) {
        return usersService.queryByPage(pageNo, pageSize, username);
    }

    @GetMapping("queryUserListByName")
    public Object queryUserListByName(String name) {
        return usersService.queryUserListByName(name);
    }

    @GetMapping("queryUserByNicknameAndUsername")
    public Object queryUserByNicknameAndUsername(String username, String nickname) {
        return usersService.queryUserByNicknameAndUsername(username, nickname);
    }

    @GetMapping("queryUserPageByNicknameAndUsername")
    public Object queryUserPageByNicknameAndUsername(
            @RequestParam(required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(required = false, defaultValue = "1") Integer pageSize,
            @RequestParam(required = false, defaultValue = "") String username,
            @RequestParam(required = false, defaultValue = "") String nickname) {
        return usersService.queryUserPageByNicknameAndUsername(pageNo, pageSize, username, nickname);
    }
}

